<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author:LJQ <liujiqi@etrol.com>
// +-----------------------------------------------------------------------

namespace app\duty\model;

use app\common\model\Base;
use app\common\model\User;
use app\basic\model\Enterprise;
use app\basic\model\Hazard;
use app\plan\model\Plan;

/**
 * 消息管理
 */
class Events extends Base{
	

	protected $name = 'event';
	protected $createTime = 'createTime';
	protected $updateTime = 'updateTime';
	
	public $statusTypeList=[] ;
	public $eventTypeList=[] ;


	public  function getType(){

	 $statusType=db('basicinfo')->where(array('sysCode'=>30))->column('subsystemName','subsystemNo');
	 $this->statusTypeList=$statusType;
	 return $this->statusTypeList;
	}

	public  function getEventType(){

	 $statusType=db('basicinfo')->where(array('sysCode'=>20))->column('subsystemName','subsystemNo');
	 $this->eventTypeList=$eventType;
	 return $this->eventTypeList;
	}

	public function setStartTimeAttr($value,$data){
	    return strtotime($value);	
	}




	public function getstatusAttr($value,$data){
		$this->getType();
		if($data['status']){
			return $this->statusTypeList[$data['status']];
		}
		return null;
	}



	public function user() {
		return $this->hasOne(User::class,'id','receiveId');
	}

	public function enterprise(){

		return $this->hasOne(Enterprise::class,'id','enterpriseId');
	}

	public function hazard(){

		return $this->hasOne(Hazard::class,'id','dangerSourceId');
	}

	public function plan(){

		return $this->hasOne(Plan::class,'id','reservePlanId');
	}

	public function script()
	{
		return $this->belongsToMany('User','roleaccess','roleId','id');
	}



}